package io.renren.modules.jxgk.controller;

import io.renren.common.annotation.SysLog;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import io.renren.modules.jxgk.entity.ClassDiaryEntity;
import io.renren.modules.jxgk.entity.ClassDiaryTeacherSum;
import io.renren.modules.jxgk.entity.TeacherDiary;
import io.renren.modules.jxgk.service.ClassDiaryTableService;
import io.renren.modules.jxgkphone.tempEntity.TempStudentAttendence;
import io.renren.modules.sys.entity.SysUserEntity;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.wuwenze.poi.ExcelKit;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("ClassDiaryTable/")
public class ClassDiaryTableController {

    @Autowired
    ClassDiaryTableService classDiaryService;

    @RequestMapping("Select")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        List<ClassDiaryEntity> cse = classDiaryService.queryList(query);
        int total = classDiaryService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(cse, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }
    @RequestMapping("SelectOfMyCollege")
    public R SelectOfMyCollege(@RequestParam Map<String, Object> params){
        //查询列表数据
        String college = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getCollege();
        params.put("college",college);
        Query query = new Query(params);

        List<ClassDiaryEntity> cse = classDiaryService.queryList(query);
        int total = classDiaryService.queryTotal(query);

            PageUtils pageUtil = new PageUtils(cse, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }
    @RequestMapping("SelectChidaoZaotui")
    public R SelectChidaoZaotui(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        List<ClassDiaryEntity> cse = classDiaryService.queryChidaoZaotuiList(query);
         int total = classDiaryService.queryChidaoZaotuiTotal(query);

        PageUtils pageUtil = new PageUtils(cse, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }


    @RequestMapping("getClassDiaryTableByTeacherAndClassCourse")
    public R getClassDiaryTableByTeacherAndClassCourse(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        List<TeacherDiary> cse = classDiaryService.getClassDiaryTableByTeacherAndClassCourse(query);
        int total = classDiaryService.getClassDiaryTotalByTeacherAndClassCourse(query);

        PageUtils pageUtil = new PageUtils(cse, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }


    @RequestMapping("SelectTeacherSum")
    public R SelectTeacherSum(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        List<ClassDiaryTeacherSum> cse = classDiaryService.queryClassDiaryTeacherSumList(query);
        int total = classDiaryService.queryClassDiaryTeacherSumTotal(query);

        PageUtils pageUtil = new PageUtils(cse, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }


    @RequestMapping("teacherSumExport")
    public R teacherSumExport(HttpServletResponse response,String searching,String college,String year,String term){
        //查询列表数据
        Map<String,Object> map=new HashMap<String,Object>();
        List<ClassDiaryTeacherSum> cse = null;
        if(searching!=null&&!searching.equals("")){
            map.put("searching",searching);
        }
        if(college!=null&&!college.equals("")){
            map.put("college",college);
        }
        if(year!=null&&!year.equals("")){
            map.put("year",year);
        }
        if(term!=null&&!term.equals("")){
            map.put("term",term);
        }
        try{
            cse=classDiaryService.queryClassDiaryTeacherSumList(map);

            ExcelKit.$Export(ClassDiaryTeacherSum.class, response).toExcel(cse, "教师授课情况汇总");
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return R.ok();
    }

    @RequestMapping("exportjqGrid1Excel")
    public R exportjqGrid1Excel(HttpServletResponse response,String courseTeacherId,String courseName,String year,String term,String className,String title){
        //查询列表数据
        Map<String,Object> map=new HashMap<String,Object>();
        List<TeacherDiary> cse = null;
        if(courseTeacherId!=null&&!courseTeacherId.equals("")){
            map.put("courseTeacherId",courseTeacherId);
        }
        if(courseName!=null&&!courseName.equals("")){
            map.put("courseName",courseName);
        }
        if(year!=null&&!year.equals("")){
            map.put("year",year);
        }
        if(term!=null&&!term.equals("")){
            map.put("term",term);
        }
        if(className!=null&&!className.equals("")){
            map.put("className",className);
        }
        try{
            cse = classDiaryService.getClassDiaryTableByTeacherAndClassCourse(map);

            ExcelKit.$Export(TeacherDiary.class, response).toExcel(cse, title);
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return R.ok();
    }

    @RequestMapping("/export")
    public R export(HttpServletResponse response, String teacherName) {
        List<ClassDiaryEntity> cse = null;
        Map<String,Object> map=new HashMap<String,Object>();
        if(teacherName!=null&&!teacherName.equals("")){
            map.put("teacherName",teacherName);
        }
        try{
            cse=classDiaryService.queryList(map);
            ExcelKit.$Export(ClassDiaryEntity.class, response).toExcel(cse, "教师授课情况");
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return R.ok();
    }

}